import type { App } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHashHistory } from 'vue-router';
import { setupPageGuard } from './permission';
import { ChatLayout } from '@/views/chat/layout';
import mjlayout from '@/views/mj/layout.vue';
import leftChat from '@/views/weChat/leftChat.vue';
import userRateLayOut from '@/layout/userRateLayOut.vue';
import friendSocialLayOut from '@/layout/friendSocialLayOut.vue';
import userMangeLayOut from '@/layout/userMangeLayOut.vue';
import privateModelLayOut from '@/layout/privateModelLayOut.vue';
import companyMangeLayOut from '@/layout/companyMangeLayOut.vue';
import lumalayout from '@/views/luma/layout.vue';
import storelayout from '@/views/store/layout.vue';
import fanyilayout from '@/views/fanyi/layout.vue';
import pptlayout from '@/views/ppt/layout.vue';
import musiclayout from '@/views/suno/layout.vue';
import knowledgelayout from '@/views/knowledge/layout.vue';
import wxlayout from '@/views/wxbot/layout.vue';

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Home',
    component: leftChat,
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/index.vue')
      }
    ]
  },
  {
    path: '/userRate',
    name: 'userRate',
    component: userRateLayOut,
    redirect: '/userRate',
    children: [
      {
        path: '/userRate/tagManage',
        name: 'tagManage',
        component: () => import('@/views/userRate/tagManage.vue')
      },
      {
        path: '/userRate/bulkSending/index',
        name: 'bulkSending',
        component: () => import('@/views/userRate/bulkSending/index.vue')
      },
      {
        path: '/userRate/SOPbulkSending/index',
        name: 'SOPbulkSending',
        component: () => import('@/views/userRate/SOPbulkSending/index.vue')
      },
      {
        path: '/userRate/humanIntervention',
        name: 'humanIntervention',
        component: () => import('@/views/userRate/humanIntervention.vue')
      },
      {
        path: '/userRate/wechatNotice',
        name: 'wechatNotice',
        component: () => import('@/views/userRate/wechatNotice.vue')
      },
      {
        path: '/userRate/autoGreet',
        name: 'autoGreet',
        component: () => import('@/views/userRate/autoGreet.vue')
      },
      {
        path: '/userRate/friendVerify',
        name: 'friendVerify',
        component: () => import('@/views/userRate/friendVerify.vue')
      },
      {
        path: '/userRate/textConfig',
        name: 'textConfig',
        component: () => import('@/views/userRate/textConfig.vue')
      }
    ]
  },
  {
    path: '/friendSocial',
    name: 'friendSocial',
    component: friendSocialLayOut,
    redirect: '/friendSocial',
    children: [
      {
        path: '/friendSocial/sendSocial',
        name: 'sendSocial',
        component: () => import('@/views/friendSocial/sendSocial.vue')
      },
      {
        path: '/friendSocial/SOPSocial',
        name: 'SOPSocial',
        component: () => import('@/views/friendSocial/SOPSocial.vue')
      },
      {
        path: '/friendSocial/findSocial',
        name: 'findSocial',
        component: () => import('@/views/friendSocial/findSocial.vue')
      },
      {
        path: '/friendSocial/aiThumbsUpReview',
        name: 'aiThumbsUpReview',
        component: () => import('@/views/friendSocial/aiThumbsUpReview.vue')
      }
    ]
  },
  {
    path: '/userMange',
    name: 'userMange',
    component: userMangeLayOut,
    redirect: '/userMange',
    children: [
      {
        path: '/userMange/userMangePath',
        name: 'userMangePath',
        component: () => import('@/views/userMange/userMangePath.vue')
      },
      {
        path: '/userMange/loseUser',
        name: 'loseUser',
        component: () => import('@/views/userMange/loseUser.vue')
      },
      {
        path: '/userMange/deleteUser',
        name: 'deleteUser',
        component: () => import('@/views/userMange/deleteUser.vue')
      },
      {
        path: '/userMange/customerPool',
        name: 'customerPool',
        component: () => import('@/views/userMange/customerPool.vue')
      },
      {
        path: '/userMange/generateReport',
        name: 'generateReport',
        component: () => import('@/views/userMange/generateReport.vue')
      }
    ]
  },
  {
    path: '/privateModel',
    name: 'privateModel',
    component: privateModelLayOut,
    redirect: '/privateModel',
    children: [
      {
        path: '/privateModel/aiTrain',
        name: 'aiTrain',
        component: () => import('@/views/privateModel/aiTrain.vue')
      },
      {
        path: '/privateModel/takeoverSettings',
        name: 'takeoverSettings',
        component: () => import('@/views/privateModel/takeoverSettings.vue')
      },
      {
        path: '/privateModel/switchModel',
        name: 'switchModel',
        component: () => import('@/views/privateModel/switchModel.vue')
      }
    ]
  },
  {
    path: '/companyMange',
    name: 'companyMange',
    component: companyMangeLayOut,
    redirect: '/companyMange',
    children: [
      {
        path: '/companyMange/staffMange',
        name: 'staffMange',
        component: () => import('@/views/companyMange/staffMange.vue')
      },
      {
        path: '/companyMange/departmentMange',
        name: 'departmentMange',
        component: () => import('@/views/companyMange/departmentMange.vue')
      },
      {
        path: '/companyMange/wechatMange',
        name: 'wechatMange',
        component: () => import('@/views/companyMange/wechatMange.vue')
      },
      {
        path: '/companyMange/powerMange',
        name: 'powerMange',
        component: () => import('@/views/companyMange/powerMange.vue')
      },
      {
        path: '/companyMange/scriptApprova',
        name: 'scriptApprova',
        component: () => import('@/views/companyMange/scriptApprova.vue')
      }
    ]
  },
  {
    path: '/chat',
    name: 'Root',
    component: ChatLayout,
    redirect: '/chat',
    children: [
      {
        path: '/chat/:uuid?',
        name: 'Chat',
        component: () => import('@/views/chat/index.vue')
      }
    ]
  },
  {
    path: '/wechat',
    name: 'weChat',
    component: leftChat,
    redirect: '/wechat/index',
    children: [
      {
        path: '/wechat/:uuid?',
        name: 'jlweChat',
        component: () => import('@/views/weChat/index.vue')
      }
    ]
  },
  {
    path: '/g',
    name: 'g',
    component: ChatLayout,
    redirect: '/g/g-2fkFE8rbu',
    children: [
      {
        path: '/g/:gid',
        name: 'GPTs',
        component: () => import('@/views/chat/index.vue')
      }
    ]
  },
  {
    path: '/m',
    name: 'm',
    component: ChatLayout,
    redirect: '/m/gpt-3.5-turbo',
    children: [
      {
        path: '/m/:gid',
        name: 'Model',
        component: () => import('@/views/chat/index.vue')
      }
    ]
  },
  {
    path: '/draw',
    name: 'Rootdraw',
    component: mjlayout,
    redirect: '/draw/index',
    children: [
      {
        path: '/draw/:uuid?',
        name: 'draw',
        component: () => import('@/views/mj/draw.vue')
      }
    ]
  },

  {
    path: '/fanyi',
    name: 'Fanyi',
    component: fanyilayout,
    redirect: '/fanyi/index',
    children: [
      {
        path: 'index',
        name: 'fanyi',
        component: () => import('@/views/fanyi/index.vue')
      }
    ]
  },

  {
    path: '/ppt',
    name: 'Ppt',
    component: pptlayout,
    redirect: '/ppt/index',
    children: [
      {
        path: 'index',
        name: 'ppt',
        component: () => import('@/views/ppt/index.vue')
      }
    ]
  },

  {
    path: '/video',
    name: 'Video',
    component: lumalayout,
    redirect: '/video/index',
    children: [
      {
        path: '/video/:uuid?',
        name: 'video',
        component: () => import('@/views/luma/video.vue')
      }
    ]
  },

  {
    path: '/music',
    name: 'Music',
    component: musiclayout,
    redirect: '/music/index',
    children: [
      {
        path: '/music/:uuid?',
        name: 'music',
        component: () => import('@/views/suno/music.vue')
      }
    ]
  },

  {
    path: '/store',
    name: 'Store',
    component: storelayout,
    redirect: '/store/t',
    children: [
      {
        path: 't',
        name: 'store',
        component: () => import('@/views/store/appList.vue')
      }
    ]
  },

  {
    path: '/wxbot',
    name: 'Wxbot',
    component: wxlayout,
    redirect: '/wxbot/t',
    children: [
      {
        path: 't',
        name: 'wxbot1',
        component: () => import('@/views/wxbot/bot.vue')
      }
    ]
  },
  {
    path: '/knowledge',
    name: 'Knowledge',
    component: knowledgelayout,
    redirect: '/knowledge/t',
    children: [
      {
        path: 't',
        name: 'knowledge1',
        component: () => import('@/views/knowledge/index.vue')
      }
    ]
  },

  {
    path: '/annex',
    name: 'Annex',
    component: knowledgelayout,
    redirect: '/annex/t',
    children: [
      {
        path: 't',
        name: 'annex1',
        component: () => import('@/views/knowledge/annex.vue')
      }
    ]
  },

  {
    path: '/fragment',
    name: 'Fragment',
    component: knowledgelayout,
    redirect: '/fragment/t',
    children: [
      {
        path: 't',
        name: 'fragment1',
        component: () => import('@/views/knowledge/fragment.vue')
      }
    ]
  },

  {
    path: '/404',
    name: '404',
    component: () => import('@/views/exception/404/index.vue')
  },

  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue')
  },

  {
    path: '/regist',
    name: 'regist',
    component: () => import('@/views/regist/index.vue')
  },
  {
    path: '/resetpassword',
    name: 'resetpassword',
    component: () => import('@/views/resetpassword/index.vue')
  },

  {
    path: '/500',
    name: '500',
    component: () => import('@/views/exception/500/index.vue')
  },

  {
    path: '/:pathMatch(.*)*',
    name: 'notFound',
    redirect: '/404'
  }
];

export const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior: () => ({ left: 0, top: 0 })
});

setupPageGuard(router);

export async function setupRouter(app: App) {
  app.use(router);
  await router.isReady();
}
